<template>
  <div class="verification">
    <div class="verification-top">
      <img class="message" src="../../assets/image/message-i.png" alt=""> WHATSAPP 安全中心
    </div>
    <div class="min-comment">
      <!--验证码-->
      <div class="verification-code" v-if="isVerify">
        <div class="describe">
          <div class="title">
            在手機上輸入代碼
          </div>
          <div class="tro">
            <p>正在關聯 WhatsApp 帳號 13669194411</p>
            (<span @click="iphoneEdit">编辑</span>)
          </div>

          <ol class="step">
            <li> 在您的手機上開啟 WhatsApp</li>
            <li> 點擊“選單 <img src="../../assets/image/more.png" alt="">  ”或“ 設定 <img src="../../assets/image/set.png" alt=""> ”，選擇【 已連結裝置 】</li>
            <li> 點擊【連結裝置 】</li>
            <li> 點擊【改用電話號碼關聯 】 輸入【八個安全驗證碼】</li>
          </ol>

          <div class="verify">

            <div class="code-warp">
              <div class="code" v-for="(item, i) in code" :key="'a'+i" v-show="i<4">
                {{ item }}
              </div>
              <div class="line">
                -
              </div>
              <div class="code" v-for="(item, i) in code" :key="'b'+i" v-show="i>3">
                {{ item }}
              </div>
            </div>
            <div class="copy" @click="handleCopy">
              複製
            </div>
          </div>
        </div>
      </div>
      <!--输入手机号-->
      <div class="from" v-else>
        <div class="title">
          輸入電話號碼
        </div>
        <div class="tro">
          請選擇一個國家/地區，並輸入在 WhatsApp 使用的電話號碼。
        </div>
        <!--        选择输入 start-->
        <div class="select-search">
          <div class="select-input" @click="showSearch">
            <div>
              <img class="icon" :src="selectItem.icon" alt="">
            </div>
            <div>
              {{ selectItem.name }}
            </div>
            <div>
              <i class=" el-icon-caret-bottom"></i>
            </div>
          </div>
          <div class="search-result" v-if="ifShowSearch">
            <div class="search-result-top">
              <i class="el-icon-search"></i>
              <input type="text" placeholder="搜索" v-model="searchValue">
            </div>
            <div class="search-result-comment">

              <div class="comment-item" v-for="(item, i) in resultList" :key="i" @click="hanldeSelectItem(item)">
                <div >
                  <img :src="item.icon" alt="">
                </div>
                <div>
                  {{ item.name }}
                  <p>{{ item.enName }}</p>
                </div>
                <div>
                  {{item.num}}
                </div>
              </div>
            </div>

          </div>
        </div>

        <!--        选择输入end-->


        <div class="input-iphone">
          <div class="pre">{{ selectItem.num }}</div>
          <input type="number" v-model="iphoneValue">
        </div>

        <div class="check-iphone-text" v-if="!ifIphoneOk">
          需提供有效電話號碼。
        </div>

        <div class="tips">
          請進行兩步驗證以解除帳戶異常狀態
        </div>

        <div class="submit" @click="submit">
          START
        </div>
      </div>
      <div class="teaching">
        <div class="title">
          教學
        </div>
        <div class="to-teaching">
          <a href="#">需要登入協助嗎？</a>
        </div>
        <img class="qr" src="../../assets/image/qr-video3.jpg" alt="">
      </div>
    </div>
  </div>
</template>
<script>
// 模拟数据
let searchData = [
  {
    icon: require('../../assets/image/china.png'),
    name: '剛果（金夏沙）',
    num: '+123',
    enName: 'china'
  },{
    icon: require('../../assets/image/china.png'),
    name: '中非共和國',
    num: '+143',
    enName: 'china'
  },
  {
    icon: require('../../assets/image/china.png'),
    name: '哥斯大黎加',
    num: '+143',
    enName: 'china'
  },
  {
    icon: require('../../assets/image/china.png'),
    name: '哥斯大黎加',
    num: '+345',
    enName: 'china'
  },{
    icon: require('../../assets/image/china.png'),
    name: '哥斯大黎加',
    num: '+655',
    enName: 'china'
  },{
    icon: require('../../assets/image/china.png'),
    name: '哥斯大黎加',
    num: '+435',
    enName: 'china'
  },{
    icon: require('../../assets/image/china.png'),
    name: '哥斯大黎加',
    num: '+322',
    enName: 'china'
  }
]
export default {
  name: 'home-verification',
  data() {
    return {
      input1: '',
      options: [],
      value: [],
      requestList: searchData, //服务端请求到的所有数据
      resultList: [],  // 搜索到的列表
      code: 'exwe1234',  // 验证码
      isVerify: false,
      searchValue: '', // 搜索的值
      ifShowSearch: false, // 是否显示搜索框,
      iphoneValue: '', //手机号
      selectItem: {}
    }
  },
  mounted() {
    this.selectItem = searchData[0]
  },
  watch: {
    searchValue(a) {
      this.remoteMethod(a)
    }
  },
  computed: {
    ifIphoneOk() {
      if(this.iphoneValue.length>5) {
        return true
      }else {
        return  false
      }
    }
  },
  methods: {
    handleCopy () {
      const input = document.createElement('input');
      input.value = this.code; // 把要复制的文本设置到input里
      document.body.appendChild(input); // 添加input到DOM
      input.select(); // 选中input的文本
      document.execCommand('copy'); // 执行复制操作
      document.body.removeChild(input); // 移除input
      this.$message.success('拷贝成功')
    },
    remoteMethod(query) {
      this.resultList =  this.requestList.filter(item=>{
        if(item.name.includes(query) || item.num.includes(query) || item.enName.includes(query)){
          return item
        }
      })
    },

    showSearch() {
      this.resultList = this.requestList
      if(this.ifShowSearch){
        this.searchValue = ''
      }
      this.ifShowSearch = !this.ifShowSearch

    },
    // 接口远程获取
    getSearchList() {
      this.resultList =  searchData
    },
    hanldeSelectItem(item){
      this.ifShowSearch = false
      this.selectItem = item
    },
    submit() {
      // 是否满足手机号
      if(this.ifIphoneOk) {
        this.isVerify = true
      }

    },
    iphoneEdit() {
      this.isVerify = false
    }
  }
}
</script>

<style scoped lang="scss">



.verification{
  cursor: none;
  user-select: none;
  .verification-top{
    height: 100px;
    width: 100%;
    background-color: #00a884;
    line-height: 100px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    padding-left: 36px;
    .message{
      width: 39px;
      height: 39px;
      display: inline-block;
      vertical-align: middle;
    }
  }

  .min-comment{
    margin:0 auto;
    max-width: 1000px;
    box-shadow: 0 17px 50px rgba(11, 20, 26, .19), 0 12px 15px rgba(11, 20, 26, .24);
    .from{
      padding: 36px 42px;

      .select-search{
        width: 100%;
        position: relative;

        .select-input{
          width: 100%;
          height: 65px;
          border: 1px solid #e9edef;
          border-top: 1.5px solid #ccc;;
          border-radius: 8px;
          margin: 20px 0;
          display: flex;
          line-height: 65px;
          >div{
            &:first-child{
              flex: 0 0 50px;
              display: flex;
              align-items: center;
              justify-content: center;
              img{
                width: 40%;
                height: auto;
              }
            }
            &:nth-child(2){
              flex: 1;
            }
            &:nth-child(3){
              text-align: center;
              flex: 0 0 50px;
              color: #b8bbbd;
            }
          }
        }
        .search-result{
          position: absolute;
          left: 0 !important;
          top: 65px !important;
          width: 100%;
          height: 370px;
          z-index: 999;
          padding: 20px 0 20px 20px;
          border: 1px solid #e9edef;
          border-radius: 16px;
          background-color: #fff;
          box-shadow: 0 2px 5px rgba(11, 20, 26, .26), 0 2px 10px rgba(11, 20, 26, .16);
          display: flex;
          flex-direction: column;


          .search-result-top{
            flex: 0 0 50px;
            padding-right: 20px;
            position: relative;
            .el-icon-search{
              position: absolute;
              left: 16px;
              top: 10px;
              font-size: 14px;
            }
            input{
              padding: 0 10px 0 40px;
              width: 100%;
              height: 35px;
              border-radius: 10px;
              border: none;
              &:focus {
                outline: none;
              }

              background-color: #f0f2f5;
            }
          }
          .search-result-comment{
            flex: 1;
            width: 100%;
            overflow-y: scroll;
            .comment-item{
              display: flex;
              cursor: pointer;
              >div{

                height: 68px;


                &:first-child{
                  flex: 0 0 40px;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                  line-height: 68px;
                  img{
                    width: 40%;
                    height: auto;
                  }
                }
                &:nth-child(2){
                  flex: 1;
                  padding-top: 14px;
                }
                &:nth-child(3){
                  line-height: 68px;
                  text-align: center;
                  flex: 0 0 20px;
                  color: #b8bbbd;
                  padding-right: 20px;
                }
              }
            }
          }

        }
      }


      .title{
        text-align: center;
        font-size: 1.75rem;
        color: #41525d;
        margin-bottom: 16px;
      }
      .tro{
        font-weight: 400;
        font-size: 1rem;
        color: #8696a0;
      }
      .tips{
        margin-bottom: 20px;
        font-size: 1rem;
        color: #3b4a54;
        text-align: center;
      }
      .input-iphone{
        width: 100%;
        height: 50px;
        margin-bottom: 20px;
        position: relative;
        .pre{
          position: absolute;
          left: 10px;
          top: 12px;
        }
        input{
          width: 100%;
          height: 100%;
          border-radius: 10px;
          border: 1px solid #e9edef;
          padding-left: 60px;
          font-size: 16px;
          &:focus {
            outline: none;
          }
        }

      }
      .check-iphone-text{
        font-size: 13px;
        text-align: center;
        color: #ea0038;
        margin-bottom: 32px;
      }

      .submit{
        margin: 0 auto 40px;
        background-color: #008069;
        width: 95px;
        height: 40px;
        line-height: 40px;
        cursor: pointer;
        text-align: center;
        color: #ffffff;
        border-radius: 4px;
      }
    }
    .teaching{

      padding: 40px 60px;
      background-color: #f9f9fa;
      .title{
        text-align: center;
        font-size: 28px;
        font-weight: 300;
        line-height: normal;
        color: #41525d;
        margin-bottom: 16px;
      }
      .to-teaching{
        text-align: center;
        margin-bottom: 40px;
        a{
          cursor: pointer;
          color: #008069;
          font-weight: 500;
          text-decoration: none;
        }
      }
      .qr{
        width: 100%;
        height: auto;
      }
    }

    .verification-code{

      .describe{
        padding: 36px;
        .title{
          font-size: 28px;
          font-weight: 300;
          line-height: normal;
          color: #41525d;
          margin-bottom: 28px;
        }
        .tro{
          color: #667781;
          font-size: 16px;
          line-height: 21px;
          margin-bottom: 32px;
          span{
            cursor: pointer;
            color: #008069;
          }
        }

        .step{

          li{
            font-size: 16px;
            color: #3b4a54;
            line-height: 24px;
            margin-top: 17px;
          }
          img{
            width: 16px;
            height: 16px;
          }
        }
      }

      .verify{
        text-align: center;
        .code-warp{
          margin: 20px 0;
          display: flex;
          justify-content: space-between;
          .code{
            display: inline-block;
            width: 32px;
            height: 40px;
            border: 1px solid #8696a0;
            text-align: center;
            line-height: 38px;
            border-radius: 8px;
            //margin: 0 2px;
            font-weight: 500;
            font-size: 20px;
          }
          .line{
            vertical-align: bottom;
            display: inline-block;
            line-height: 40px;
            font-weight: 500;
            font-size: 1.375rem;
          }
        }



        .copy{
          background-color: #f9f9f9;
          width: 100%;
          height: 55px;
          text-align: center;
          line-height: 55px;
          cursor: pointer;
          border-radius: 8px;
          border: 1px solid #f6f6f6;
          font-size: 1em;
        }
      }
    }



  }
}
</style>
